<?php
class Back_Model_Mapper_Saisons extends Jnd_Model_Mapper_Abstract
{
    protected $_dict = array(
        "id" => "id_saison", 
        "nom" => "nom", 
        "ouverte" => "ouverte", 
        "dateDebut" => "date_debut", 
        "dateFin" => "date_fin",
        "parDefaut" => "defaut"
    );
    protected $_dictDate = array(
        "dateDebut" => "date_debut", 
        "dateFin" => "date_fin"
    );

    /**
     *
     * @see Jnd_Model_Mapper_Abstract::getDataFromDict()
     */
    protected function getDataFromDict( Jnd_Model_Abstract $objetModel )
    {
        $donnees = parent::getDataFromDict($objetModel);
        return $donnees;
    }
    
    /**
     * Fonction permettant d'initialiser la requête Select
     * @return Zend_Db_Table_Select
     */
    private function _creationSelect($table) {
        $select = new Zend_Db_Table_Select($table);
        return $select;
    }
    
    public function saisons() {
        $table = $this->_getTable();
        $select = $this->_creationSelect($table);
        $select->from($table->info(Zend_Db_Table::SCHEMA) . "." . $table->info(Zend_Db_Table::NAME), array($this->getDict("id")), $table->info(Zend_Db_Table::SCHEMA));
        $stmt = $select->query();
        $resultats = $stmt->fetchAll();
        
        return $this->unmapArray($resultats);
    }
    
    public function recuperationSaisonDefaut() {
        $table = $this->_getTable();
        $select = $this->_creationSelect($table);
        $select->where($this->getDict('parDefaut') . "=?", 1, Zend_Db::INT_TYPE);
        
        $stmt = $select->query();
        $resultat = $stmt->fetch();
        if ($resultat === false) {
            return false;
        }
        $resultat = $this->unmap($resultat);
        
        return $resultat;
    }
    
}

